{extend name="base:base" /}
{block name="body"}

<div class="layui-fluid">
    
    
<div class="well">

    <dl>
        <dd>地址：<?php echo config('database.hostname'); ?> </dd>
        <dd> 数据库：<?php echo config('database.database'); ?></dd>


        <?php
        $result1 = [];
        array_walk($tables, function($value, $key) use (&$result1) {
            array_push($result1, $value['table_name']);
        });

        $result2 = [];
        array_walk($lists, function($value, $key) use (&$result2) {
            array_push($result2, $key);
        });
        ?>
        <dt> <b>多出来的表 ：</b> </dt>
        <?php
        foreach (array_diff($result1, $result2) as $key => $value) {
            ?>
            <dd><?php echo $value; ?></dd>
        <?php } ?>

    </dl>






</div>
    
    <table class="layui-table">
        <thead>
            <tr>
                <th>标准表</th>
            </tr>
        </thead>
        <tbody>

            <?php
            $table_array = [];
            foreach ($tables as $key => $value) {
                array_push($table_array, $value['table_name']);
            }

            foreach ($lists as $key => $value) {
                ?>

                <tr <?php
                if (!in_array($key, $table_array)) {
                    echo 'class="danger"';
                }
                ?>>
                    <td><?php
                        echo $key;
                        if (!in_array($key, $table_array)) {
                            echo ' <b>不存在</b>';
                        }
                        ?>



                    </td>

                </tr>
                <tr>
                    <td >


                        <table class="table table-bordered" >
                            <col style="width: 200px" />
                            <col style="width: 200px" />
                            <col style="width: 200px" />
                            <col style="width: 200px" />

                            <tbody>

                                <?php
                                foreach ($value as $key2 => $value2) {

                                    // 表字段 
                                    ?>

                                    <tr>
                                        <td><?php echo $key2; ?></td>
                                        <td><?php echo $value2[1]; ?></td>
                                        <td><?php echo $value2[0]; ?></td>
                                        <td>

                                            <?php
                                            // dd($table_fields);

                                            if (in_array($key, $table_array)) {

                                                $table_fields = \think\Db::query('SHOW FULL COLUMNS FROM ' . $key . ' ');

                                                foreach ($table_fields as $key3 => $value3) {
                                                    if ($key2 == $value3['Field']) {
                                                        echo '<font color="green">存在</font>';

                                                        // 检查类型
                                                        if (strpos($value3['Type'], $value[$key2][1]) !== false) {
                                                            echo ' <font color="blue">类型正确</font>';
                                                        }
                                                    } else {
                                                        continue;
                                                    }
                                                }
                                            }
                                            ?>

                                        </td>
                                        <td></td>
                                    </tr>
                                <?php } ?>


                            </tbody>
                        </table>


                    </td>
                </tr>

            <?php } ?>



        </tbody>
    </table>
</div>






{/block}